import java.util.Comparator;
import java.util.Objects;
import java.util.PriorityQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 晓星航
 * Date: 2023-04-10
 * Time: 20:51
 */
class Card implements Comparable<Card>{
    public int rank; // 数值
    public String suit; // 花色
    public Card(int rank, String suit) {
        this.rank = rank;
        this.suit = suit;
    }
    //ctrl + i 快速实现接口
    @Override
    public int compareTo(Card o) {
        return this.rank - o.rank;
    }
    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        //getClass() != o.getClass() 比较的是：是不是同一个类型
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Card card = (Card) o;
        return rank == card.rank && Objects.equals(suit,card.suit);
    }

    @Override
    public String toString() {
        return "Card{" +
                "rank=" + rank +
                ", suit='" + suit + '\'' +
                '}';
    }
}
class RankComparator implements Comparator<Card> {

    @Override
    public int compare(Card o1, Card o2) {
        return o1.rank - o2.rank;
    }
}
public class TestDemo {
    public static void main(String[] args) {
        Card card1 = new Card(1,"♥");
        Card card2 = new Card(2,"♥");
        PriorityQueue<Card> priorityQueue = new PriorityQueue<>(new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o1.rank - o2.rank;
            }
        });
        priorityQueue.offer(card1);//直接放到了Queue数组的0下标
        priorityQueue.offer(card2);
        System.out.println(priorityQueue);
        System.out.println(card1.equals(card2));
    }
    public static void main2(String[] args) {
        PriorityQueue<Card> priorityQueue = new PriorityQueue<>();
        Card card1 = new Card(1,"♥");
        Card card2 = new Card(2,"♥");
        System.out.println(card1.compareTo(card2));//大于返回1 等于返回0 小于返回-1

    }
    public static void main1(String[] args) {
        PriorityQueue<Card> priorityQueue = new PriorityQueue<>();
        priorityQueue.offer(new Card(2,"♥"));//直接放到了Queue数组的0下标
        priorityQueue.offer(new Card(1,"♥"));
        priorityQueue.offer(new Card(3,"♥"));
        System.out.println(priorityQueue);

    }
}
